Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds rawBody support to Node.js #2064

Conversation

christopheranderson
Copy link
Contributor

@christopheranderson christopheranderson commented Oct 24, 2017

(BLOCKED) Requires changes from Azure/azure-functions-nodejs-worker#48

Please review the PR above which will unblock this PR by allowing me to pull in the NuGet. Tests will fail until that's in.

fixes #1951

@dnfclas
Copy link

dnfclas commented Oct 24, 2017

@christopheranderson,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@christopheranderson
Copy link
Contributor Author

christopheranderson commented Oct 24, 2017

Integration tests fail. Guess I don't know which tests that AppVeyor runs on PRs. I was just running the tests wrong locally.

@fabiocav
Copy link
Member

Which integration tests are you referring to? I see a green run for this PR

@@ -252,4 +252,5 @@ message RpcHttp {
string status_code = 12;
map<string,string> query = 15;
bool is_raw = 16;
TypedData rawBody = 17;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this will always be a string, so you can concretely type it as a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it's not always a string, sometimes it's None. I could have created a new type which only has those types, but I opted to reuse the existing TypedData object since it wasn't very opinionated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - in those cases, would not setting rawBody be sufficient? Protobuf doesn't require all properties to be set in a message, so I think that all client libs will handle the None case. I'd suggest that this change is scoped only to node, which definitely handles nullables. To enable this behavior for node & other workers in the future we could pass the body bytes directly to the client, where they can determine rawbody

That said, I'm on vacation and TypedData works. Just my 2¢ :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't set it, it's null. null !== undefined which is a breaking behavior. protobuf for Node.js doesn't seem to have an option for "null" - looks like a fun thread: protocolbuffers/protobuf#1606

@christopheranderson
Copy link
Contributor Author

@fabiocav / @mathewc any feedback before I merge this in?

@@ -109,6 +111,7 @@ public static TypedData ToRpc(this object value)
var bytes = new byte[length];
request.Body.Read(bytes, 0, length);
body = bytes;
rawBody = bytes.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give you the type name. Use Encoding.UTF8.GetString (or appropriate encoding)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to make sure you have a failing test for this before fixing :)

@fabiocav
Copy link
Member

Merged in a97d137

@fabiocav fabiocav closed this Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node Http Request : Provide access to raw request body
4 participants